Public Class clsPdfDictionnary
#Region "Private members"
    Private _dictionnary As Hashtable '(of ClsPdfBaseObject)
    Private _dirty As Boolean   'True if the dictionnary has been modified
    Private _objectNumber As Long
    Private _generationNumber As Long
#End Region
#Region "Constructors"
    Friend Sub New()
        _dictionnary = New Hashtable
        _init()
    End Sub
    Friend Sub New(ByVal dict As Hashtable)
        _dictionnary = dict
        _init()
    End Sub
#End Region
#Region "Friend Properties"
    Friend Property Dirty() As Boolean
        Get
            Dirty = _dirty
        End Get
        Set(ByVal value As Boolean)
            _dirty = value
        End Set
    End Property
    Friend Property GenerationNumber() As Long
        Get
            GenerationNumber = _generationNumber
        End Get
        Set(ByVal value As Long)
            _generationNumber = value
        End Set
    End Property
    Friend Property ObjectNumber() As Long
        Get
            ObjectNumber = _objectNumber
        End Get
        Set(ByVal value As Long)
            _objectNumber = value
        End Set
    End Property
    Protected Friend Property Hashtable() As Hashtable
        Get
            Hashtable = _dictionnary
        End Get
        Set(ByVal value As Hashtable)
            _dictionnary = value
        End Set
    End Property
#End Region
#Region "Friend Methods"
    Friend Sub Modified()
        _dirty = True
    End Sub
    Friend Sub Add(ByVal key As String, ByVal obj As clsPdfBaseObject)
        'If with have duplicated keys, we keep the first that was added
        '(PDF standard state that if we have a duplicated key, its value is undefined)
        If Not _dictionnary.ContainsKey(key) Then
            _dictionnary.Add(key, obj)
        End If
    End Sub
    Friend Sub Add(ByVal key As String, ByVal obj As clsPdfBaseObject, ByVal overwrite As Boolean)
        If overwrite Then
            If _dictionnary.ContainsKey(key) Then
                'We overwrite its value
                _dictionnary.Remove(key)
            End If
        End If

        If Not _dictionnary.ContainsKey(key) Then
            Add(key, obj)
        End If
    End Sub
    Friend Sub Remove(ByVal key As String)
        If _dictionnary.ContainsKey(key) Then
            _dictionnary.Remove(key)
        End If
    End Sub
    Friend Function Item(ByVal key As String) As clsPdfBaseObject
        Item = Nothing
        If _dictionnary.ContainsKey(key) Then
            Item = TryCast(_dictionnary.Item(key), clsPdfBaseObject)
        End If
    End Function
    Friend Function ContainsKey(ByVal key As String) As Boolean
        ContainsKey = _dictionnary.ContainsKey(key)
    End Function
    Friend Function GetDate(ByVal token As String) As String
        Dim obj As clsPdfBaseObject
        GetDate = ""
        obj = Item(token)
        If Not obj Is Nothing Then
            GetDate = obj.GetDate
        End If
    End Function
    Friend Function GetString(ByVal token As String) As String
        Dim obj As clsPdfBaseObject
        GetString = ""
        obj = Item(token)
        If Not obj Is Nothing Then
            GetString = obj.GetString
        End If
    End Function
    Friend Function GetLong(ByVal token As String) As Integer
        Dim obj As clsPdfBaseObject
        GetLong = 0
        obj = Item(token)
        If Not obj Is Nothing Then
            GetLong = obj.GetLong
        End If
    End Function
    Friend Function GetArray(ByVal token As String) As List(Of clsPdfBaseObject)
        Dim obj As clsPdfBaseObject
        GetArray = Nothing
        obj = Item(token)
        If Not obj Is Nothing Then
            GetArray = obj.GetArray
        End If
    End Function
    Friend Function GetBoolean(ByVal token As String) As Boolean
        Dim obj As clsPdfBaseObject
        GetBoolean = False
        obj = Item(token)
        If Not obj Is Nothing Then
            GetBoolean = obj.GetBoolean
        End If
    End Function
    Friend Function GetRectangle(ByVal token As String) As PdfRectangle
        Dim obj As clsPdfBaseObject
        GetRectangle = Nothing
        obj = Item(token)
        If Not obj Is Nothing Then
            GetRectangle = obj.GetRectangle
        End If
    End Function
#End Region
#Region "Private Methods"
    Private Sub _init()
        _objectNumber = 0
        _generationNumber = 0
        _dirty = False
    End Sub
#End Region
End Class
